package com.sunday.frame;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;

import com.sunday.msq.widget.LoadingDialog;

/**
 * Created by SunshineHu on 2015/3/20.
 * 通用基类activity
 */
public abstract class BaseActivity extends Activity{

    protected Activity mActivity;//Activity 实例
	
	private LoadingDialog loadingDialog;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mActivity=this;
        AppManager.INSTANCE.addActivity(this);//加入activity管理
        try {
            InjectUtil.Inject(this);
        } catch (Exception e) {
            e.printStackTrace();
            return;
        }
        createActivity();
    }

    protected abstract void createActivity();//抽象方法,用来代替oncreate

    @Override
    protected void onDestroy() {
        super.onDestroy();
        disMiss();//dismiss check fangzhi leak
        HttpTool.cancelRequest(this);
        AppManager.INSTANCE.finishActivity(this);//移除activity
    }
    
	/**
	 * 显示进度加载
	 */
	protected void show(String message) {
		if (loadingDialog == null) {
			loadingDialog = LoadingDialog.createDialog(this);
			// 点击外部区域，是否消失loadingDialog
			loadingDialog.setCanceledOnTouchOutside(false);
		}
		if(message.equals("")){
			message="正在加载";
		}
		loadingDialog.setMessage(message);
		loadingDialog.show();
	}

	/**
	 * 关闭进度加载
	 */
	protected void disMiss() {
		if (loadingDialog != null) {
			loadingDialog.dismiss();
			loadingDialog = null;
		}
	}
    
	/**
	 * 返回按钮
	 */
	public void back(View v){
		finish();
	}

}
